<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>激活卡统计报表</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="js/getCardPermission.js" type="text/javascript"></script>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<style type="text/css">
.scroll_body {
	height: 300px;
	overflow: scroll;
	overflow-x: hidden;
	padding: 20px 100px 0;
	margin-bottom: 20px;
}
.fr {
	float: right;
}
.fl {
	float: left;
}
.w_50 {
	width: 50%;
}
label {
	padding-right: 20px;
}
/* 清除浮动 */
.clear::after {
	clear:both;
	content:'.';
	display:block;
	width: 0;
	height: 0;
	visibility:hidden;
}/*==for FF/chrome/opera/IE8==*/
.div_body {
	padding: 20px;
}
.h_30 {
	height: 30px;
}

</style>
<script type="text/javascript">
    /* init */
    $(function () {
    	// 查询页面数据
    	queryReportList(1)
    })
    // 查询激活卡模板数据 整理参数 lfd添加注释 20181031
	function queryCardInfo(displayPage){
 		var name= $("#name").val();
		var id = $("#carDefindId").val();
		loadCardData({current:displayPage,size:10,name: name, id: id}); 
	}
	// 查询激活卡模板数据 查询 lfd添加注释 20181031
	function loadCardData(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
 		$.ajax({
			url : "cardreport/cardReportPage",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;

				var radioObj ="<input class='input_fxk' name='checkBoxCard' type='radio' value='#'>";
				var fieldNames = "name@TDH,id@TDH,name,id";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#prodTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(param.current,6,page.maxPage,"75");
				var pageDIV = $("#prodPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				$("#prodDiv").OpenDiv();
				
			}
		}) 
	}
	// 无用 废弃  lfd 20181031
	/* function datedivClose1() {
		$('#mstartNo').val('')
		$('#mendNo').val('')
		$('#date1').val('')
		closeCurrentDIV('dateDiv1')
	} */
	/**
	 * 数据过滤 start
	 * treeId 对应 zTree 的 treeId，便于用户操控
	 * parentNode 进行异步加载的父节点 JSON 数据对象
	 * 异步加载获取到的数据转换后的 Array(JSON) / JSON / String 数据对象
	 */
	function filter(treeId, parentNode, childNodes) {
		if (!childNodes) return null;
		var newChildNodes = $.map(childNodes, function (v, i) {
			var item = {
				'id': v.deptCode,
				'pid': v.snrDept,
				'name': v.deptCname,
				'isParent': true
			}
			return item
		})
		return newChildNodes;
	}
	// 数据过滤 end
	// 选择机构 start
	function selectDept() {
		var treeObj = $.fn.zTree.getZTreeObj("ztree");
		var nodes = treeObj.getSelectedNodes();
		if(nodes.length!=0){
			$('#comCode').val(nodes[0].id)
			$.fn.zTree.destroy("ztree");// 销毁机构树
			closeDeptDiv()
		}else{
			$.message("error", "请选择机构！");
		}
	}
	// 选择机构 end
	// 显示弹窗  start
	function openDeptDiv() {
		menuTreeInit()// 机构树初始化
		window.setTimeout(function () {
			$('#deptDiv').OpenDiv();// 打开弹窗
		},1000)
	}
	// 显示弹窗  end
	// 机构列表初始化 start 
	function menuTreeInit() {
		// ztree 配置
		var setting = {
			view: {
				selectedMulti: false,
				showIcon: false
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId"
				}
			},
			async: {
				enable: true,
				url:"cardPower/querycompanydown",// 查询下级机构
				autoParam:["id"],
				dataFilter: filter,
				dataType: 'json'
			}
		};
		// 展示机构树
		$.fn.zTree.init($("#ztree"), setting);
	}
    // 初始化 end 
	// 机构弹窗关闭 lfd添加注释 20181031
	function closeDeptDiv() {
		closeCurrentDIV('deptDiv')
	}
    // 卡模板弹窗关闭 lfd添加注释 20181031
	function closeProdDiv(){
		closeCurrentDIV('prodDiv')
		$('#name').val("");
		$('#carDefindId').val("");
	}
    // 关闭弹窗 通用 lfd添加注释 20181031
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
    // 打开卡模板弹窗 lfd添加注释 20181031
	function openProdDiv(){
		queryCardInfo(1)
	}
    // 导出数据 lfd添加注释 20181031
	function exportReport(){
		var comCode=$("#comCode").val();
		var status=$("#status").val();
		var IdStr=$('#cardId').val();
		if(!comCode){
			$.message("error", "请选择机构！");
			return
		}
		/* if(!status){
			$.message("error", "请选择状态！");
			return
		} */
	   	if(!IdStr){
	   		// 更改错误提示 lfd changed 20181031
	   		$.message("error", "请选择卡定义！");
			// $.message("error", "请至少选择一张激活卡！");
			return
		}
		//20190226 路径找不到bug修改 start
	  	//window.location.href="cardreport/exportReportExcelForCard?deptNo="+ comCode +"&IdStr="+ IdStr;
	    window.open('<%=basePath%>'+"cardreport/exportReportExcelForCard?deptNo="+ comCode +"&IdStr="+ IdStr);
        //20190226 路径找不到bug修改 end
    }
    // 选择激活卡 lfd添加注释 20181102
	function chooseProd(){
	   	if($("input[name='checkBoxCard']:checked").length == 0){
	        // 更改错误提示 lfd changed 20181102
			// $.message("error", "请至少选择一张激活卡！");
			$.message("error", "请选择卡定义名称！");
			return
		}
		var cardNameList = $.map($("input[name='checkBoxCard']:checked").parent().next(), function (v, i) {
			return $(v).html();
		});
		var cardIdList = $.map($("input[name='checkBoxCard']:checked").parent().next().next(), function (v, i) {
			return $(v).html();
		});
		var nameStr=cardNameList.join(",");
		var idStr=cardIdList.join(",");
		$('#cardName').val(nameStr);
		$('#cardId').val(idStr); 
		closeProdDiv();
	}
    // 根据条件查询数据 整理数据 lfd添加注释 20181102
	function queryReportList(displayPage){
		var comCode=$("#comCode").val();
		var status=$("#status").val();
		var IdStr=$('#cardId').val();
		loadCardData1({current:displayPage,size:10,deptNo:comCode,status:status,IdStr:IdStr});
	}
    // 根据条件查询数据 查询 lfd添加注释 20181102
	function loadCardData1(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
			$.ajax({
			url : "cardreport/cardPageForReport",
			type : 'POST',
			async : true,
			dataType:'json',
			data:jsonDate,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;
				startP = page.current;
				var fieldNames = "deptNo,name,sumFrame,modalPremamtPp,notCommamt,yesCommamt,yesApp,yesDiscard,wckMoney,yckMoney,yappMoney,ydiscardMoney,id@TDH";
				var lastColumnElement ="<input type='button' class='input_button_1' value='详情' onClick='details(this)' />";
				var firstColumnElement= null;
				var tableContent = creatTable1(fieldNames, page,firstColumnElement,lastColumnElement);
				var tableObj = $("#cardpageTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(startP,6,page.maxPage,"81");
				var pageDIV = $("#cardpageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
			}
		}) 
	}
	// 点击详情 查询 lfd changed 20181102 ------------------start
	function details(obj) {
		// $(obj).parent().parent().children().css('background', '#ECF5FC')
		var $tr = $(obj).parent().parent().children()
		var deptNo = $(obj).parent().parent().children()[0].innerHTML.split("-")[0]
		var IdStr= $(obj).parent().parent().children()[12].innerHTML
		// 八位机构没有详情
		if(deptNo.length==8){
            $.message("error", "暂无下级机构");
            return;
        }
		// 查询详情页面
		self.location.href="<%=path%>/cardreport/details?deptNo=" + deptNo + "&IdStr=" + IdStr
	}
	// 点击详情 查询 lfd changed 20181102 ------------------end
    // 点击详情 查询 lfd添加注释 20181102
	/* function details(obj) {
		var str = $(obj).parent().parent().children()[0].innerHTML
	    var deptNo= str.split("-")[0]
		if(deptNo.length==8){
			$.message("error", "暂无下级机构");
			return;
		}
		var IdStr= $(obj).parent().parent().children()[10].innerHTML
		jsonDate={deptNo:deptNo,IdStr:IdStr};
		$.openLoading();
		$.ajax({
		url : "cardreport/queryDetails",
		type : 'POST',
		async : true,
		dataType:'json',
		data:jsonDate,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			if(page.data.length==0){
				$.message("error", "暂未查到数据");
				return;
			}
			startP = page.current;
			var fieldNames = "deptNo,name,sumFrame,modalPremamtPp,notCommamt,yesCommamt,yesApp,wckMoney,yckMoney,yappMoney,id@TDH";
			var lastColumnElement ="<input type='button' class='input_button_1' value='详情' onClick='details(this)' />";
			var firstColumnElement= null;
			var tableContent = creatTable1(fieldNames, page,firstColumnElement,lastColumnElement);
			var tableObj = $("#detailsTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			// var strPage = creatChannelPage(startP,6,page.maxPage,"79");
			// var pageDIV = $("#detailsPageDIV");
			// pageDIV[0].innerHTML="";
			// pageDIV.append(strPage); 
			
			
			// TODO
			// $("#detailsDiv").OpenDiv();
		}
	})  
	}  */
	 // TODO 关闭详情弹窗
	/* function closeDetailsDiv(){
		closeCurrentDIV('detailsDiv')
		
	} */
</script>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td><img src="./images/current_1.jpg"></td>
					<td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style="color: #136bab;">激活卡管理 <span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>
							激活卡统计报表
					</span></td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>

	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="50%" height="30">
						机构代码:
						<input id="comCode" type="text" class="input_text" disabled>
						<input type="button" class="input_button_1 open_btn" id="" value="选择" onClick="openDeptDiv()" />
						<input type="hidden" id="cardId" value="">
						</td>
						
						<td width="50%" height="30">
						卡定义名称： <input id="cardName" type="text" class="input_text" disabled>
                    <input type="button" class="input_button_1 open_btn" id="" value="选择" onClick="openProdDiv()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
            <td>
                <table class="search_table">
                    <tr height="30px">
                        <td width="30%" height="30">
                            <input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryReportList(1)" />
                            <input type="button" class="input_button_1" id="export" value="导出" onClick="exportReport()" /> 
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
		<!-- 数据列表 start -->
		<tr>
			<td>
			<div class="table_box ">
				<table id="cardpageTable" class="content_table_1">
					<thead>
						<tr class="f1">
								<th style="width: 6%">机构</th>
								<th style="width: 5%">卡定义名称</th>
								<th style="width: 3%">总数</th>
								<th style="width: 3%">每单保费</th>
								<th style="width: 3%">未出库数</th>
								<th style="width: 3%">可激活数</th>
								<th style="width: 3%">已激活数</th>
                                <th style="width: 3%">作废数</th>
								<th style="width: 3%">未出库金额</th>
								<th style="width: 3%">可激活金额</th>
								<th style="width: 3%">已激活金额</th>
                                <th style="width: 3%">作废金额</th>
								<th style="width: 2%">操作</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				</div>
				<div id="cardpageDIV" class="page"></div>
			</td>
		</tr>
		<!-- 数据列表 end -->
	</table>
		<!-- begin ------------------------- DIV 默认隐藏--------------------------->
	<div id="deptDiv" style="display: none; width: 50%;">
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="./images/closedown.gif" alt="关闭"
						onclick="closeDeptDiv()" /></td>
				</tr>
			</table>
		</div>
		<div class="table_title_body scroll_body">
			<ul class="ztree" id="ztree">
			</ul>
		</div>
		<div align="center">
			<input class="input_button_3" type="button" onclick="selectDept()" value="确定">&nbsp;&nbsp; 
			<input class="input_button_3" type="button" onclick="closeDeptDiv()" value="取消">
		</div>
	</div>
	<!-- end -------------------------DIV 默认隐藏--------------------------->
	<!-- begin -------------------------产品 DIV 默认隐藏--------------------------->
	<div id="prodDiv" style="display: none; width: 80%;">
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img
						src="./images/closedown.gif" alt="关闭"
						onclick="closeProdDiv()" /></td>
				</tr>
			</table>
		</div>

		<table class="table_02" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td style="border: 0px; text-align: right;">卡定义名称：</td>
							<td style="border: 0px; text-align: left;"><input
								name="txt3" id="name" class="input_text"
								style="width: 120px;" value=""></td>
							<td style="border: 0px; text-align: right;">卡定义号：</td>
							<td style="border: 0px; text-align: left;"><input
								name="txt3" id="carDefindId" class="input_text"
								style="width: 120px;" value="">&nbsp;&nbsp;&nbsp;&nbsp; <input type="button"
								class="input_button_1" id="searchBtn" value="查询"
								onClick="queryCardInfo(1)" /></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="prodTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width: 5%">选择</th>
								<th style="width: 45%">卡定义名称</th>
								<th style="width: 50%">卡定义号</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="prodPageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
			<input class="input_button_3" type="button"
				onclick="chooseProd()" value="确定">&nbsp;&nbsp; <input
				class="input_button_3" type="button" onclick="closeProdDiv()"
				value="取消">
		</div>
	</div>
	<!-- begin ------------------------- 详情DIV 默认隐藏--------------------------->
	<!-- <div id="detailsDiv" style="display: none; width: 95%;">
		<div class="table_title_div">
			<table class="table_title" style='width: 100%; height: 20px;'>
				<tr>
					<td width="100%"></td>
					<td width="100%" id="interfaceName"></td>
					<td width="200%" align="right"><img
						src="./images/closedown.gif" alt="关闭"
						onclick="closeDetailsDiv()" /></td>
				</tr>
			</table>
		</div>

		<table class="table_02" align="center">
			<tr>
				<td>
					<table id="detailsTable" class="content_table_1" >
						<thead>
							<tr class="f1">
								<th style="width: 5%">机构</th>
								<th style="width: 5%">卡名称</th>
								<th style="width: 2%">总数</th>
								<th style="width: 2%">每单保费</th>
								<th style="width: 2%">未出库数</th>
								<th style="width: 2%">已出库数</th>
								<th style="width: 2%">已激活数</th>
								<th style="width: 2%">未出库金额</th>
								<th style="width: 2%">已出库金额</th>
								<th style="width: 2%">已激活金额</th>
								<th style="width: 2%">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="detailsPageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
			 <input class="input_button_3" type="button" onclick="closeDetailsDiv()" value="确定">
		</div>
	</div> -->
	<!-- end -------------------------详情 DIV 默认隐藏--------------------------->
</body>
</html>